// Qt on Metro test application
// Copyright (c) Andrew Knight
// This software is licensed under the MIT: http://www.opensource.org/licenses/MIT
// This software uses Qt (http://qt.nokia.com)

#include <QtGui/QApplication>
#include <QtCore/QTimer>
#include "canvastest.h"
#include "../metro/metroapplication.h"

#include <QtGui/QLabel>
#include <QtCore/QtPlugin>
#include <QtCore/QPluginLoader>
#include <QDebug>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    Q_INIT_RESOURCE(metro);
    Q_IMPORT_PLUGIN(metro);

    MetroApplication* metroApp;
    foreach(QObject* plugin, QPluginLoader::staticInstances()) {
        qDebug() << plugin;
        if ((metroApp = qobject_cast<MetroApplication*>(plugin))) {
            qDebug() << "success!";
            break;
        }
    }

    if(!metroApp) {
        qDebug() << "Could not initialize Metro plugin";
        return 1;
    }

    CanvasTest w(metroApp);
    w.show();

    QTimer timer;
    QObject::connect(&timer, SIGNAL(timeout()), &w, SLOT(onRender()));
    timer.start(60);

    metroApp->start();

    // Use this to simulate the marshalled event loop in QtMetroStub
    /*while(true){
        qApp->processEvents();
    }*/

    return a.exec();
}
